package vn.aptech.scrumgroup.model;

import vn.aptech.scrumgroup.event.MoveRoundEvent;
import vn.aptech.scrumgroup.event.MoveRoundListener;
import vn.aptech.scrumgroup.physic.Vector2d;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.Path;
import demo.axitdn.physic.Unit;

public class ArrowOnCircleModel extends AbstractBaseModel implements OnCircle{

	private CircleWithTextModel circle1;
	private CircleWithTextModel circle2;

	
	public ArrowOnCircleModel(CircleWithTextModel circle1, CircleWithTextModel circle2, int backColor) {
		// TODO Auto-generated constructor stub
		super(backColor, -1);
		this.circle1 = circle1;
		this.circle2 = circle2;
	}
	
	@Override
	public void actionPerformed(MoveRoundEvent evt) {
		// TODO Auto-generated method stub
		
	}


	@Override
	public void setCircle(CircleWithTextModel model) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public CircleWithTextModel getCircle() {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public void moveRoundOnCircle(float angle) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void addMoveRoundListener(MoveRoundListener listener) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public boolean isPointOf(float x, float y) {
		// TODO Auto-generated method stub
		return false;
	}

	@Override
	public void changeColor(int color) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void onDraw(Canvas c) {
		// TODO Auto-generated method stub
		Paint paint = new Paint();
		paint.setColor(backColor);
		float dx = (circle2.getCx()-circle1.getCx());
		float dy = (circle2.getCy()-circle1.getCy());
		float d = (float)Math.sqrt(dx*dx+dy*dy);
		float xH = 65*((circle2.getCx()-circle1.getCx()))/132+circle1.getCx();
		float yH = 65*((circle2.getCy()-circle1.getCy()))/132+circle1.getCy();
		float xI = 80*((circle2.getCx()-circle1.getCx()))/132+circle1.getCx();
		float yI = 80*((circle2.getCy()-circle1.getCy()))/132+circle1.getCy();
		paint.setStrokeWidth(d/16);
		c.drawLine(xH, yH, xI, yI, paint);
		Vector2d vI = new Vector2d((xI-circle1.getCx()),yI-circle1.getCy());
	    vI.rotation((float) (-Math.PI/24));
	    float xB = vI.getX()+circle1.getCx();
	    float yB = vI.getY()+circle1.getCy();
		vI.rotation((float) (Math.PI/12));
		float xC = vI.getX()+circle1.getCx();
		float yC = vI.getY()+circle1.getCy();
		float xA = 85*((circle2.getCx()-circle1.getCx()))/132+circle1.getCx();
		float yA = 85*((circle2.getCy()-circle1.getCy()))/132+circle1.getCy();
		drawTriangle(c,xA,yA,xB,yB,xC,yC,paint);
	}//end onDraw

	private void drawTriangle(Canvas c, float xA, float yA, float xB, float yB,
			float xC, float yC, Paint paint) {
		// TODO Auto-generated method stub
		Path path = new Path();
        path.moveTo(xA, yA);
        path.lineTo(xB, yB);
        path.lineTo(xC, yC);
        path.lineTo(xA, yA);
        path.close();
        paint.setStrokeWidth(Unit.i);
        Paint paint2 = new Paint();
        paint2.setStyle(Paint.Style.FILL);
        paint2.setAntiAlias(true);
        paint2.setARGB(230, 231, 60, 10);
        c.drawPath(path, paint2);
	}//end drawTriangle

	@Override
	public void onUpdate(double t) {
		// TODO Auto-generated method stub
		
	}

}
